import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class JavaBasicDemo {

	/**
	 * 第一章
	 */
	public static void demo1_1() {
		System.out.println("\t购物清单");
		System.out.println("品名\t数量\t单价\t总价");
		System.out.println("品名\t数量\t单价\t总价");
		System.out.println("品名\t数量\t单价\t总价");

	}

	/**
	 * 第二章 变量和表达式 程序里的一些值需要保存起来， 变量存储在内存空间里，变量的值可以改变 如果通过内存地址来寻找变量，太复杂了麻烦了
	 */
	public static void demo2_1() {
		// System.out.println(a/b);
		int x = 123;
		int a1, b1, c1;
		a1 = x % 10;
		b1 = (x / 10) % 10;
		c1 = x / 100;
		System.out.println("个位为：" + a1 + "\t十位：" + b1 + "\t" + c1);
		int y = 1234;
		int d1 = y % 10;
		int e1 = y / 10 % 10;
		int f1 = y / 100 % 10;
		int g1 = y / 1000;
		System.out.println("个位为：" + d1 + "\t" + "十位为:" + e1 + "\t" + "位为:" + f1
				+ "\t" + "千位为：" + g1);
		char ch1 = ',';
		char ch2 = '0';
		boolean ret = ch1 == ch2;
		System.out.println(ret);
		x = 123;
		System.out.println(x >= 10 && x <= 100);
		int year = 2014;
		System.out.println(year % 4 == 0 && year % 100 != 0 || year % 400 == 0);

	}

	public static void demo2_2() {

		int y = 10000000;
		System.out.println("1:");
		System.out.println(y >= 100 && y < 1000 || y >= 10000 && y < 100000);
		char ch = '*';
		System.out.println("2:");
		System.out.println(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z');
		System.out.println("3:");
		System.out.println(ch < '0' && ch > '9');
		System.out.println("4:");
		System.out.println(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z'
				|| ch >= '0' && ch <= '9');
		y = 204;
		System.out.println("5:");
		System.out.println(y % 4 == 0 && y % 5 != 0 && y >= 100 && y <= 200);

		y = 234;
		int n1 = y / 100;
		int n2 = y / 10 % 10;
		int n3 = y % 10;
		System.out.println("6:");
		System.out.println(n1 + "\t" + n2 + "\t" + n3);
		System.out.println((n1 * n1 * n1 + n2 * n2 * n2 + n3 * n3 * n3) == y);
		System.out.println("7:");
		System.out.println(n1 + n2 > n3 && n1 + n3 > n2 && n2 + n3 > n1);
		int user = 2;
		int cpu = 3;
		System.out.println("8:");
		System.out.println(user == 2 && cpu == 1 || user == 3 && cpu == 2
				|| user == 1 && cpu == 3);
	}

	public static void demo3_1() {
		System.out.println("请输入一个数字x：");
		Scanner input = new Scanner(System.in);
		int x = input.nextInt();
		input.close();
		if (x > 0) {
			System.out.println("输入的数字为正数");
		} else if (x == 0) {
			System.out.println("输入的数字为0");
		} else {
			System.out.println("输入的数字为负数");
		}
	}

	public static void demo3_2() {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入一个年份year：");
		int year = input.nextInt();
		input.close();
		if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
			System.out.println("输入的年份:" + year + ",为闰年。");
		} else {
			System.out.println("输入的年份:" + year + ",不是闰年。");
		}

		int x = 20;
		int y = x++ + x++ + x++;// (x+x) y=40 x++ x=21 40+21 x++
		int x1 = 10;
		int y1 = 20;
		x1 += y1; // x1=10+20=30
		y1 = x1 - y1;// y1=30-20=10
		x1 -= y1;// x1=x1-y1=30-10=20
		System.out.println("x1=" + x1 + "\ty1=" + y1);
		/*
		 * 三目表达式
		 */
		int stuNum = 27;
		int p = 5;
		int count = stuNum % p == 0 ? stuNum / p : stuNum / p + 1;
		System.out.println("房间数：" + count);
		x1 = 70;
		y1 = 50;
		int z1 = 90;
		int max = x1 > y1 && x1 > z1 ? x1 : y1 > z1 ? y1 : z1;
		max = x1 > y1 ? x1 > z1 ? x1 : z1 : y1 > z1 ? y1 : z1;
		System.out.println("最大数：" + max);
		// 短路与 短路或
		x1 = 20;
		y1 = 10;
		boolean n5 = x1 <= y1 && ++y1 > 10;// ++y1 不执行
		n5 = x1 >= y1 || ++y1 > 10; // ++y1 不执行
		System.out.println("最大数：" + n5);
		int m1 = 10;
		char m2 = 'a';
		float m3 = 5.5f;
		double m4 = 6.7;
		double m5 = m1 + m2 + m3 + m4;// 精度以精度最大变量为准
		int m6 = (int) (m5 - 10);// 错误！double to int 丢失
	}

	public static void demo3_3() {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入成绩：");
		int score = input.nextInt();
		if (score >= 90) {
			System.out.println("A");
		} else if (score >= 80) {
			System.out.println("B");
		} else if (score >= 70) {
			System.out.println("C");
		} else if (score >= 60) {
			System.out.println("D");
		} else {
			System.out.println("E");
		}

	}

	/*
	 * 1,if(true){}
	 * 
	 * 2,if(true){} else{}
	 * 
	 * 3,if(true){} else if(){} else if(){} else if(){} else if(){} else{} 4,
	 * switch case
	 */
	public static void demo3_4() {
		// 输入等级A-E，输出对应的分数段
		Scanner input = new Scanner(System.in);
		System.out.println("请输入等级：");
		char ch = input.next().charAt(0);
		ch = (char) (ch >= 'a' && ch <= 'z' ? ch - 32 : ch);
		switch (ch) {
			case 'A' :
				System.out.println(">=90");
				break;
			case 'B' :
				System.out.println(">=80");
				break;
			case 'C' :
				System.out.println(">=70");
				break;
			case 'D' :
				System.out.println(">=60");
				break;
			case 'E' :
				System.out.println("<60");
				break;
			default :
				System.out.println("等级输入有误！");
				break;
		}
	}

	public static void demo3_5() {
		// 输入等级A-E，输出对应的分数
		int ch;
		do {
			System.out.println("1，新游戏");
			System.out.println("2，游戏配置");
			System.out.println("3，退出");
			Scanner input = new Scanner(System.in);
			System.out.println("请输入游戏菜单（1-3）：");
			ch = input.nextInt();

		} while (ch < 1 || ch > 3);

		switch (ch) {
			case 1 :
				System.out.println("开始新游戏");
				break;
			case 2 :
				System.out.println("进行游戏配置");
				break;
			case 3 :
				System.out.println("游戏退出，再见！");
				break;
			default :
				System.out.println("菜单选择有误！");
				break;
		}
	}

	public static void demo3_6() {
		System.out.println("开始石头剪刀布游戏：");
		System.out.println("\t1，石头");
		System.out.println("\t2，剪刀");
		System.out.println("\t3，布");
		Scanner input = new Scanner(System.in);
		System.out.println("请玩家出拳（1-3）：");
		int user = input.nextInt();
		Random random = new Random();
		int x = random.nextInt(3) + 1;
		PrintChuquan(x, "电脑");
		PrintChuquan(user, "玩家");
		if (user == x) {
			System.out.println("\n哇，势均力敌，平局！");
		} else if (user == 1 && x == 2 || user == 2 && x == 3
				|| user == 3 && x == 1) {
			System.out.println("\n太厉害了，玩家胜！");
		} else {
			System.out.println("\n好可惜呀，你输了！");
		}
	}

	public static void PrintChuquan(int chuquan, String name) {
		switch (chuquan) {
			case 1 :
				System.out.println(name + "出拳：石头");
				break;
			case 2 :
				System.out.println(name + "出拳：剪刀");
				break;
			case 3 :
				System.out.println(name + "出拳：布");
				break;
			default :
				System.out.println(name + "乱出拳，视为作弊！");
				break;
		}
	}

	public static void demo3_9() {
		int x = 16;
		double y = Math.sqrt(16);
		System.out.print(y);

	}

	public static void demo4_1() {
		int i = 0;
		int sum = 0;
		while (i <= 100) {
			sum += i++;

		}
		System.out.println("1+2+3+4+...+100=" + sum);

	}

	public static void demo4_2() {
		int i = 100;
		int j = 1;
		int a, b, c, sum;// 个，十，百，和
		while (i < 1000) {
			a = i % 10;
			b = i / 10 % 10;
			c = i / 100;
			sum = a * a * a + b * b * b + c * c * c;
			if (sum == i) {
				System.out.println("第" + j + "个水仙花数：" + i);
				j++;
			}
			i++;
		}
	}

	public static void demo4_3() {
		int i = 1000;
		int j = 1;
		int a, b, c, d, sum;// 个，十，百，千，和
		while (i < 10000) {
			a = i % 10;
			b = i / 10 % 10;
			c = i / 100 % 10;
			d = i / 1000;
			sum = (int) (Math.pow(a, 4) + Math.pow(b, 4) + Math.pow(c, 4)
					+ Math.pow(d, 4));
			if (sum == i) {
				System.out.println("第" + j + "个玫瑰花数：" + i);
				j++;
			}
			i++;
		}
	}

	public static void demo4_4() {
		int ch;
		do {
			System.out.println("1，新游戏");
			System.out.println("2，游戏配置");
			System.out.println("3，退出");
			Scanner input = new Scanner(System.in);
			System.out.println("请输入游戏菜单（1-3）：");
			ch = input.nextInt();
			switch (ch) {
				case 1 :
					System.out.println("开始新游戏");
					break;
				case 2 :
					System.out.println("进行游戏配置");
					break;
				case 3 :
					System.out.println("游戏退出，再见！");
					break;
				default :
					System.out.println("菜单选择有误！");
					break;
			}

		} while (ch != 3);

	}

	public static void demo4_5() {
		Scanner input = new Scanner(System.in);
		String string, newString = "";
		int i = 0;
		char ch;
		System.out.println("请输入一个字符串：");
		string = input.next();
		int len = string.length();
		while (i < len) {
			ch = string.charAt(i);
			if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z') {
				newString += ch;
			}
			i++;
		}
		System.out.print(newString);
	}

	public static void demo4_6() {
		Scanner input = new Scanner(System.in);
		int num, i = 0;
		Random random = new Random();
		char ch;
		final String conString = "01234567890abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPRSTUVWXY";
		int len = conString.length();
		String string = "";
		System.out.println("请输入数字：");
		num = input.nextInt();
		while (i < num) {
			ch = conString.charAt(random.nextInt(len - 1));
			string += ch;
			i++;
		}
		System.out.print(string);
	}

	public static void demo4_7() {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入整数1：");
		int x = input.nextInt();
		System.out.println("请输入整数2：");
		int y = input.nextInt();
		int z, i = 2;
		if (y > x) {
			z = x;
			x = y;
			y = z;
		}
		if (x % y == 0) {
			System.out.print("最大公倍数为" + x);
			return;
		} else {
			while (i <= y) {
				if (i * x % y == 0) {
					System.out.print("最大公倍数为" + i * x);
					return;
				}
				i++;
			}
		}

	}

	public static void demo4_71() {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入整数1：");
		int x = input.nextInt();
		System.out.println("请输入整数2：");
		int y = input.nextInt();
		int z, i;
		if (y > x) {
			z = x;
			x = y;
			y = z;
		}
		if (x % y == 0) {
			System.out.print("最大公约数为" + y);
			return;
		} else {
			i = y / 2;
			while (i > 0) {
				if (y % i == 0 && x % i == 0) {
					System.out.print("最大公约数为" + i);
					return;
				}
				i--;
			}
		}

	}

	public static void demo4_8() {
		Scanner input = new Scanner(System.in);
		String postCode;
		System.out.println("请输入邮编：");
		postCode = input.next();
		boolean flag = false;
		int i = 0;
		int len = postCode.length();
		char ch;
		if (len != 6) {
			System.out.println("邮编位数错误！");
			return;
		} else {
			while (i < len) {
				ch = postCode.charAt(i);
				if (ch < '0' || ch > '9') {
					flag = true;
					break;
				}
				i++;
			} ;
		}
		if (flag) {
			System.out.println("输入中含非数字字符！");
		} else {
			System.out.println("邮编格式正确！");
		}
	}

	public static void demo4_9() {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入一个整数：");
		int num = input.nextInt();
		int product = 1;
		for (int i = 1; i < num + 1; i++) {
			product *= i;
		}
		System.out.println(num + "! = " + product);
	}

	public static void demo4_10() {

		Scanner input = new Scanner(System.in);
		int num, sum = 0;
		System.out.println("请输入一个整数：");
		num = input.nextInt();
		for (int i = 1; i <= num / 2; i++) {
			if (num % i == 0) {
				sum += i;
			}
		}
		// System.out.println(sum);
		if (sum == num) {
			System.out.println(num + "是完数！");
		} else {
			System.out.println(num + "不是完数！");
		}
	}

	public static void demo4_11() {
		Scanner input = new Scanner(System.in);
		String string, ext = "";
		int len, index = -1;
		System.out.println("请输入完整文件名：");
		string = input.next();
		len = string.length();
		for (int i = len - 1; i >= 0; i--) {
			if (string.charAt(i) == '.') {
				index = i;
				break;
			}
		}
		if (index != -1) {
			for (int i = index + 1; i < len; i++) {
				ext += string.charAt(i);
			}
			System.out.println("文件的扩展名：" + ext);
		} else {
			System.out.println("输入错误，扩展名不存在！");
		}
	}

	public static void demo83_1() {
		for (int i = 1; i < 10; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(j + "*" + i + "=" + i * j + "\t");
			}
			System.out.println();
		}
	}

	public static void demo83_2() {
		int m = 5;

		for (int i = 0; i < m; i++) {
			for (int j = 0; j < i; j++) {
				System.out.print(" ");
			}
			for (int j = 0; j < m; j++) {
				System.out.print("*");
			}
			System.out.println();
		}
	}

	public static void demo83_3() {
		int m = 5;

		for (int i = 0; i < m; i++) {
			for (int j = 0; j < 2 * i + 1; j++) {
				System.out.print("*");
			}
			System.out.println();
		}
	}

	public static void demo5_1() {
		int[] scores = new int[10];
		scores[0] = 50;

	}

	public static void demo5_2() {
		Random random = new Random();
		int[] arr1 = new int[10];
		for (int i = 0; i < arr1.length; i++) {
			arr1[i] = random.nextInt(100) + 100;
		}
		for (int i = 0; i < arr1.length; i++) {
			System.out.println("数组的第" + (i + 1) + "个元素为：" + arr1[i]);

		}

		// arr1中元素依次赋值给item，因此在循环体内改变item的值，对于数组对应的索引位置，无效！！！！
		for (int item : arr1) {
			System.out.println(item);
		}
		double sum = 0;
		for (int item : arr1) {
			sum += item;
		}
		System.out.println("数组内元素的平均数为" + sum / arr1.length);
	}

	public static void demo5_3() {
		Random random = new Random();
		int[] arr1 = new int[10];
		for (int i = 0; i < arr1.length; i++) {
			arr1[i] = random.nextInt(1000) + 100;
		}

		for (int i = 0; i < arr1.length; i++) {
			System.out.println("数组的第" + (i + 1) + "个元素为：" + arr1[i]);
		}

		int max = arr1[0];
		int min = arr1[0];
		for (int i = 1; i < arr1.length; i++) {
			if (arr1[i] > max) {
				max = arr1[i];
			}
			if (arr1[i] < min) {
				min = arr1[i];
			}
		}

		System.out.println("数组内元素,最小数为" + min);
		System.out.println("数组内元素,最大数为" + max);
	}

	public static void demo5_4() {
		Scanner input = new Scanner(System.in);
		final int Count = 3;
		int totalQty = 0;
		String bookName = "";
		double maxPrice = 0;
		String[] names = new String[Count];
		double[] prices = new double[Count];
		int[] qtys = new int[Count];
		double totalPrice = 0;
		for (int i = 0; i < Count; i++) {
			System.out.println("输入第" + (i + 1) + "本书名：");
			names[i] = input.next();
			System.out.println("输入单价：");
			prices[i] = input.nextDouble();
			System.out.println("输入数量：");
			qtys[i] = input.nextInt();

		}
		System.out.println("书名\t\t单价\t数量\t小计");
		for (int i = 0; i < Count; i++) {
			System.out.println(names[i] + "\t\t" + prices[i] + "\t" + qtys[i]
					+ "\t" + prices[i] * qtys[i]);
			totalPrice += prices[i] * qtys[i];
			totalQty += qtys[i];
			if (maxPrice < prices[i]) {
				maxPrice = prices[i];
				bookName = names[i];
			}
		}
		System.out.println("合计：" + totalPrice + "元，共计" + totalQty + "本书");
		System.out.println("其中，单价最高的书,书名：" + bookName + "，单价：" + maxPrice);
		input.close();
	}

	/*
	 * 查找数组中的符合要求的第一个元素
	 */

	public static void demo5_5() {

		int[] arr1 = {12, 76, 45, 21, 46, 9, 88, 77, 79, 76, 343};

		for (int i = 0; i < arr1.length; i++) {
			System.out.println("数组的第" + (i + 1) + "个元素为：" + arr1[i]);
		}

		int searchNum = 4;
		int index = -1;
		for (int i = 0; i < arr1.length; i++) {
			if (arr1[i] == searchNum) {
				index = i;
				break;
			}
		}
		if (index == -1) {
			System.out.println("数组中不存在元素“" + searchNum + "”!");
		} else {
			System.out.println(searchNum + "在数组中的索引位置为：" + index);
		}
	}

	/*
	 * 查找数组中的符合要求的最后一个元素。索引倒序循环
	 */
	public static void demo5_6() {

		int[] arr1 = {12, 76, 45, 21, 46, 9, 88, 77, 79, 77, 343};

		for (int i = 0; i < arr1.length; i++) {
			System.out.println("数组的第" + (i + 1) + "个元素为：" + arr1[i]);
		}

		int searchNum = 77;
		int index = -1;
		for (int i = arr1.length - 1; i >= 0; i--) {
			if (arr1[i] == searchNum) {
				index = i;
				break;
			}
		}
		if (index == -1) {
			System.out.println("数组中不存在元素“" + searchNum + "”!");
		} else {
			System.out.println(searchNum + "在数组中的最大索引位置为：" + index);
		}
	}

	/*
	 * 数组元素的插入
	 */
	public static void demo5_7() {

		int[] arr1 = {12, 76, 45, 77, 46, 9, 0, 0, 0, 0};
		int top = 6;
		int insertNum = 22;
		int inertIndex = 3;

		for (int i = 0; i < top; i++) {
			System.out.print(arr1[i] + "\t");
		}
		System.out.println();

		for (int i = top - 1; i >= inertIndex; i--) {
			arr1[i + 1] = arr1[i];
		}
		arr1[inertIndex] = insertNum;
		top++;
		for (int i = 0; i < top; i++) {
			System.out.print(arr1[i] + "\t");
		}

	}

	public static void demo5_8() {

		int[] arr1 = {12, 76, 45, 77, 46, 9, 0, 0, 0, 0};
		int top = 6;
		int deletIndex = 2;

		for (int i = 0; i < top; i++) {
			System.out.print(arr1[i] + "\t");
		}
		System.out.println();

		for (int i = deletIndex; i <= top - 2; i++) {
			arr1[i] = arr1[i + 1];
		}
		top--;
		for (int i = 0; i < top; i++) {
			System.out.print(arr1[i] + "\t");
		}

		ArrayList<String> list = new ArrayList<String>();
		list.add("a");
		list.add("b");
		list.add("c");
		list.remove(0);
	}

	public static void demo6_1() {
		final int Max = 10;
		for (int i = 0; i < Max; i++) {
			for (int j = 0; j < Max; j++) {
				System.out.print("*");
			}
			System.out.print("\n");

		}
	}

	public static void demo6_2() {
		final int Max = 5;
		for (int i = 0; i < Max; i++) {
			for (int j = 0; j <= i; j++) {
				System.out.print("*");
			}
			System.out.print("\n");

		}
	}

	public static void demo6_3() {
		final int Max = 5;
		for (int i = 0; i < Max; i++) {
			for (int j = 0; j < Max - i; j++) {
				System.out.print("*");
			}
			System.out.print("\n");

		}
	}

	public static void demo6_4() {
		final int Max = 10000;
		int sum;
		int count = 1;
		for (int i = 1; i <= Max; i++) {
			sum = 0;
			for (int j = 1; j <= i / 2; j++) {
				if (i % j == 0) {
					sum += j;
				}
			}
			if (sum == i) {
				System.out.println("第" + count + "个完数是：" + i);
				count++;
			}
		}
	}

	public static void demo6_5() {
		Random random = new Random();
		int[] nums = new int[10];
		int temp;
		for (int i = 0; i < nums.length; i++) {
			nums[i] = random.nextInt(100);
		}
		System.out.println("随机生成的数字依次为：");
		for (int item : nums) {
			System.out.print(item + "\t");
		}

		for (int i = 0; i < nums.length; i++) {
			for (int j = 0; j < (nums.length - i - 1); j++) {
				if (nums[j] < nums[j + 1]) {
					temp = nums[j];
					nums[j] = nums[j + 1];
					nums[j + 1] = temp;
				}
			}
		}
		System.out.println("\n排序后的数字依次为：");

		for (int i = 0; i < nums.length; i++) {
			System.out.print(nums[i] + "\t");
		}
	}

	public static void demo6_6() {
		Random random = new Random();
		int[] nums = new int[10];
		int temp;
		for (int i = 0; i < nums.length; i++) {
			nums[i] = random.nextInt(100);
		}
		System.out.println("随机生成的数字依次为：");
		for (int item : nums) {
			System.out.print(item + "\t");
		}

		for (int i = nums.length - 1; i >= 0; i--) {
			for (int j = nums.length - 1; j > nums.length - 1 - i; j--) {
				if (nums[j] < nums[j - 1]) {
					temp = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = temp;
				}
			}
		}
		System.out.println("\n排序后的数字依次为：");

		for (int i = 0; i < nums.length; i++) {
			System.out.print(nums[i] + "\t");
		}
	}

	public static void demo6_7() {
		Random random = new Random();
		int[] nums = new int[10];
		int temp;
		for (int i = 0; i < nums.length; i++) {
			nums[i] = random.nextInt(100);
		}
		System.out.println("随机生成的数字依次为：");
		for (int item : nums) {
			System.out.print(item + "\t");
		}

		for (int i = 0; i < nums.length - 1; i++) {
			for (int j = i + 1; j < nums.length; j++) {
				if (nums[i] < nums[j]) {
					temp = nums[i];
					nums[i] = nums[j];
					nums[j] = temp;
				}
			}
		}
		System.out.println("\n排序后的数字依次为：");

		for (int i = 0; i < nums.length; i++) {
			System.out.print(nums[i] + "\t");
		}
	}

	public static void demo6_8() {
		Random random = new Random();
		int[] nums = new int[10];
		for (int i = 0; i < nums.length; i++) {
			nums[i] = random.nextInt(100);
		}
		System.out.println("随机生成的数字依次为：");
		for (int item : nums) {
			System.out.print(item + "\t");
		}

		for (int i = nums.length - 1; i > 0; i--) {
			for (int j = i - 1; j > -1; j--) {
				if (nums[i] < nums[j]) {
					nums[i] = nums[i] + nums[j];
					nums[j] = nums[i] - nums[j];
					nums[i] = nums[i] - nums[j];
				}
			}
		}
		System.out.println("\n排序后的数字依次为：");

		for (int i = 0; i < nums.length; i++) {
			System.out.print(nums[i] + "\t");
		}
	}

	/*
	 * 二维数组和多维数组 arr[0][10,23,34,45,56] arr[1][11,24,34,45,56]
	 * arr[2][12,23,34,45,56] arr[3][13,23,34,45,56]
	 */
	public static void demo6_9() {

		Random random = new Random();
		int[][] arr = new int[3][4];
		for (int i = 0; i < arr.length; i++) {
			for (int j = 0; j < arr[i].length; j++) {
				arr[i][j] = random.nextInt(200);
			}
		}

		for (int[] is : arr) {
			for (int item : is) {
				System.out.print(item + "\t");
			}
			System.out.print("\n");
		}
		int indexX = 1, indexY = 1, max = arr[0][0];
		for (int i = 0; i < arr.length; i++) {
			for (int j = 0; j < arr[i].length; j++) {
				if (arr[i][j] > max) {
					max = arr[i][j];
					indexX = i + 1;
					indexY = j + 1;
				}
			}
		}
		System.out.println("Max value is " + max + ", it's located in row "
				+ indexX + ", column " + indexY + ".");

	}

	public static void demo6_10() {
		Random random = new Random();
		final int Count = 3;
		int[][] arr = new int[Count][Count];
		for (int i = 0; i < arr.length; i++) {
			for (int j = 0; j < arr[i].length; j++) {
				arr[i][j] = random.nextInt(10) + 1;
			}
		}

		for (int[] is : arr) {
			for (int item : is) {
				System.out.print(item + "\t");
			}
			System.out.print("\n");
		}
		int sum = 0;
		int len = arr.length;
		for (int i = 0; i < len; i++) {
			sum += arr[i][i];
			sum += arr[i][len - i - 1];
		}
		if (len / 2 == 1) {
			sum -= arr[len / 2][len / 2];
		}

		System.out
				.println("The sum of values in diagonal line is " + sum + ".");

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		demo7_5();
	}

	public static void demo7_1() {
		int[] arr = {1, 5, 10, 15, 20, 25};
		int j;
		for (j = 0; j <= arr.length; j++) {
			System.out.print(arr[j] + "\t");

		}
	}

	public static void demo7_2() {
		int a1 = 6, b1 = 8, c1 = 9;
		double myTriangle = getTriangleArea(a1, b1, c1);
		System.out.print(myTriangle);

	}

	public static double getTriangleArea(double a, double b, double c) {
		double area = -1;
		if (a + b > c && a + c > b && b + c > a) {
			double p = (a + b + c) / 2;
			area = Math.sqrt(p * (p - a) * (p - b) * (p - c));
		}
		return area;
	}

	public static void swap(int a, int b) {
		int temp;
		temp = a;
		a = b;
		b = temp;
	}

	public static void demo7_3() {
		int a1 = 10;
		int b1 = 20;
		swap(a1, b1);
		System.out.print("a=" + a1 + ",b=" + b1);
	}

	public static int getArrLength(int[] arr) {
		return arr.length;

	}

	public static void demo7_4() {
		int a1 = 10;
		int b1 = 20;
		swap(a1, b1);
		System.out.print("a=" + a1 + ",b=" + b1);
	}

	/*
	 * 值类型：int，double,float,char,boolean 引用类型放的是地址,Array,String
	 * 方法的参数是值类型和引用类型的差别： 本质上是一样的，都是为形参开辟新的内存空间，
	 * 区别在于值类型复制的就是值，引用类型存储的是引用值所存储的""地址
	 */

	public static void fun(int[] arr) {
		arr[0] = 100;
	}

	public static void demo7_5() {
		int[] arr = {1, 2, 3};
		fun(arr);
		System.out.print(arr[0]);
	}

	/**
	 * 
	 * @param arrA
	 *            数组1，元素类型int
	 * @param arrB
	 *            数组2，元素类型int
	 * @return 数组1和数组2的并集
	 */

	public static int[] unionArray(int[] arrA, int[] arrB) {

		return null;
	}

	/**
	 * 
	 * @param inputArr
	 *            待排序的数组，元素类型int
	 * @param signal
	 *            排序标识，该值">=0"表示升序，否则表示降序
	 */
	public static void sortingArray1(int[] inputArr, int signal) {

	}

	public static int[] sortingArray2(int[] inputArr, int signal) {
		return null;
	}
}
